from django import forms

class BootStrap:
    bootstrap_class_exclude = []
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        '''循环ModelForm中的所有字段,给每个字段的插件设置'''
        for name, field in self.fields.items():
            # '''跳过某个字段不添加以下样式'''
            # if name == "password":
            #     continue
            if name in self.bootstrap_class_exclude:
                continue
            old_class = field.widget.attrs.get('class', "")
            field.widget.attrs['class'] = '{} form-control'.format(old_class)
            field.widget.attrs['placeholder'] = '请输入%s' % (field.label,)

class BootstrapModelForm(BootStrap,forms.ModelForm):
    pass

class BootstrapForm(BootStrap,forms.Form):
    pass